function center = polygon_centroid(V)

n = size(V,1);
A = 0;
center_x = 0;
center_y = 0;

for i = 1:n
    j = mod(i, n) + 1;
    xi = V(i,1);
    yi = V(i,2);
    xj = V(j,1);
    yj = V(j,2);
    factor = xi * yj - xj * yi;
    A = A + factor;
    center_x = center_x + (xi + xj) * factor;
    center_y = center_y + (yi + yj) * factor;
end

A = 0.5 * A;
center_x = (1 / (6 * A)) * center_x;
center_y = (1 / (6 * A)) * center_y;

center = [center_x, center_y];

end